package com.trademark.script.methods;

import org.rsbuddy.widgets.Bank;

import com.rsbuddy.script.methods.Camera;
import com.rsbuddy.script.methods.Npcs;
import com.rsbuddy.script.methods.Objects;
import com.rsbuddy.script.task.Task;
import com.rsbuddy.script.wrappers.GameObject;
import com.rsbuddy.script.wrappers.Npc;

public class Banking {

	/*
	 * @param id The item to be checking for in the bank
	 * 
	 * @return Returns true if the bank contains 1 or more of the selected item;
	 * otherwise returns false
	 */
	public static boolean contains(final int id) {
		return Bank.getCount(id) >= 1;
	}

	/*
	 * Banks at anything in the order: chest, booth, banker
	 */
	public static void openBank() {
		if (Objects.getNearest(Bank.BANK_CHESTS) != null) {
			GameObject chest = Objects.getNearest(Bank.BANK_CHESTS);
			if (chest.isOnScreen()) {
				chest.interact("Use Bank chest");
				Sleeping.waitForBankOpened();
			} else if (!chest.isOnScreen()) {
				Camera.setPitch(true);
				Task.sleep(100, 200);
				Camera.turnTo(chest);
				Task.sleep(150, 250);
			}
		} else if (Objects.getNearest(Bank.BANK_BOOTHS) != null) {
			GameObject booth = Objects.getNearest(Bank.BANK_BOOTHS);
			if (booth.isOnScreen()) {
				booth.interact("Use-quickly Bank booth");
				Sleeping.waitForBankOpened();
			} else if (!booth.isOnScreen()) {
				Camera.setPitch(true);
				Task.sleep(100, 200);
				Camera.turnTo(booth);
				Task.sleep(150, 250);
			}
		}
		if (Npcs.getNearest(Bank.BANKERS) != null) {
			Npc banker = Npcs.getNearest(Bank.BANKERS);
			if (banker.isOnScreen()) {
				banker.interact("Bank Banker");
				Sleeping.waitForBankOpened();
			} else if (!banker.isOnScreen()) {
				Camera.setPitch(false);
				Task.sleep(100, 200);
				Camera.turnTo(banker);
				Task.sleep(150, 250);
			}
		}
	}
}
